package com.longxiao.service;

import com.longxiao.entity.Classroom;
import com.longxiao.mapper.ClassroomMapper;
import com.longxiao.service.util.DateUtil;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/6/1.
 */
@Service("classroomService")
public class ClassroomService {

    @Autowired
    ClassroomMapper classroomMapper;


    /**
     * 查询成功的房间列表
     * @param startTime
     * @param endTime
     * @return
     */
    public List<Classroom> selectAllClassroom(String startTime, String endTime,String tchId,String stuId, int offset, int rows) {
    	java.util.Date dStartTime = null;
        if(StringUtils.isNotEmpty(startTime)) {
        	dStartTime = DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss");
        }
        java.util.Date dEndTime = null;
        if(StringUtils.isNotEmpty(endTime)) {
        	dEndTime = DateUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss");
        }
        List<Classroom> list = classroomMapper.selectAllClassroom(dStartTime,dEndTime,tchId,stuId,offset, rows);
        return list;
    }

    public int selectAllClassroomCount(String startTime, String endTime,String tchId,String stuId) {
        java.util.Date dStartTime = null;
        if(StringUtils.isNotEmpty(startTime)) {
        	dStartTime = DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss");
        }
        java.util.Date dEndTime = null;
        if(StringUtils.isNotEmpty(endTime)) {
        	dEndTime = DateUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss");
        }
        return classroomMapper.selectAllClassroomCount(dStartTime, dEndTime,tchId,stuId);
    }

}
